<?php
use think\facade\Config;
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" type="text/css" href="<?php echo Config::get('app.static_domian')?>/layui/css/layui.css"/>
    <style type="text/css">
        body{margin:10px auto;width: 750px;}ul{margin-top:5px;}li{margin-top:3px;}.layui-form-switch{margin-top: 0;}#tree1 ul+ul{border-top: 1px dashed #e2e2e2;}
    </style>
    <script type="text/javascript" src="<?php echo Config::get('app.static_domian')?>/js/jquery-1.12.3.min.js"></script>
</head>
<body>

<form action="/file/local2" enctype="multipart/form-data" method="post">
    <input type="file" id="file" /> <br>
    <input type="button" id="upload" value="上传" />
</form>

<img src="" id="image" />

<script type="text/javascript">
    $(function () {
        $('#upload').click(function () {
            var formData = new FormData();
            formData.append("image", $("#file").get(0).files[0]);
            $.ajax({
                url:"/file/local2",
                type:'POST',
                data:formData,
                cache: false,
                contentType: false,    //不可缺
                processData: false, //不可缺
                success:function(data){

                    console.log(data)

                    if(data.status == 0){
                        $('#image').attr('src', data.url);
                    }else{

                        alert(data.msg);
                    }
                }
            });
        })
    })
</script>
</body>
</html>
